<?php
    echo doctype();
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>
            <?php
                echo $this->lang->line('verification_title');
            ?>
        </title>
        <link rel="stylesheet" type="text/css" href="<?php echo base_url() . 'css/install.css'; ?>" />
        <link rel="stylesheet" type="text/css" href="<?php echo base_url() . 'css/global.css'; ?>" />
        <script type="text/javascript" src="<?php echo base_url() . 'js/jquery-1.4.4.min.js';?>"></script>
        <script type="text/javascript" src="<?php echo base_url() . 'js/jquery.pack.js';?>"></script>
        <script type="text/javascript" src="<?php echo base_url() . 'js/common_js.js';?>"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#status").hide();
                function resetStatus()
                {
                    $("#verify").hide();
                    $("#services").hide();
                    $("#accounts").hide();
                    $("#accounts_services").hide();
                    $("#complete").hide();
                    $("#verify").html("Verifying and Initializing Settings...");
                    $("#services").html("Initializing Services...");
                    $("#accounts").html("Initializing Accounts...");
                    $("#accounts_services").html("Initializing Agent's Services...");
                    $("#complete").html("Complete...");
                    document.getElementById("verify").style.color = "#777";
                    document.getElementById("services").style.color = "#777";
                    document.getElementById("accounts").style.color = "#777";
                    document.getElementById("accounts_services").style.color = "#777";
                    document.getElementById("complete").style.color = "#777";
                }
                resetStatus();
                base_url = '<?php echo base_url(); ?>';
                $('button').click(
                    function(e)
                    {
                        e.preventDefault();
                        $("#status").show();
                        resetStatus();
                        $("#verify").show();
                        $.post(base_url + 'sync/initialize_settings/',
                            { validation_key : document.getElementById("validation_key").value, product_key : document.getElementById("product_key").value },
                            function(data)
                            {
                                if(data[1] == 1)
                                {
                                    $("#verify").html(data[0]);
                                    document.getElementById("verify").style.color = "#030";

                                    $("#services").show();
                                    $.post(base_url + 'sync/initialize_services/',
                                        function(data)
                                        {
                                            if(data[1] == 1)
                                            {
                                                $("#services").html(data[0]);
                                                document.getElementById("services").style.color = "#030";

                                                $("#accounts").show();
                                                $.post(base_url + 'sync/initialize_accounts/',
                                                    function(data)
                                                    {
                                                        if(data[1] == 1)
                                                        {
                                                            $("#accounts").html(data[0]);
                                                            document.getElementById("accounts").style.color = "#030";

                                                            $("#accounts_services").show();
                                                            $.post(base_url + 'sync/initialize_accounts_services/',
                                                                function(data)
                                                                {
                                                                    if(data[1] == 1)
                                                                    {
                                                                        $("#accounts_services").html(data[0]);
                                                                        document.getElementById("accounts_services").style.color = "#030";
                                                                        setTimeout(function()
                                                                        {
                                                                            $("#complete").show();
                                                                            document.getElementById("complete").style.color = "#030";
                                                                            setTimeout(function()
                                                                            {
                                                                                alert('Database Initialization and Verification Complete!');
                                                                                window.location.replace(base_url + 'verification/done/');
                                                                            }, 1000);
                                                                        }, 1000);
                                                                    }
                                                                    else
                                                                    {
                                                                        $("#accounts_services").html(data[0]);
                                                                        document.getElementById("accounts_services").style.color = "#C00";
                                                                    }
                                                                }, 'json'
                                                            );
                                                        }
                                                        else
                                                        {
                                                            $("#accounts").html(data[0]);
                                                            document.getElementById("accounts").style.color = "#C00";
                                                        }
                                                    }, 'json'
                                                );
                                            }
                                            else
                                            {
                                                $("#services").html(data[0]);
                                                document.getElementById("services").style.color = "#C00";
                                            }
                                        }, 'json'
                                    );
                                }
                                else
                                {
                                    $("#verify").html(data[0]);
                                    document.getElementById("verify").style.color = "#C00";
                                }
                            }, 'json'
                        );
                    }
                );
            });
        </script>
    </head>
    <body>
        <div id="container">
            <div id="leftcon">
                <div id="logo"></div>
            </div>
            <div id="content">
                <div id="install_content">
                    <h1>
                        <?php
                            echo $this->lang->line('verification_title');
                        ?>
                    </h1>
                    <label>
                        <?php
                            echo $this->lang->line('verification_valid_code');
                        ?>
                    </label>
                    <input type="text" class="ver" id="validation_key" name="validation_key" />
                        <?php

                        ?>
                    <label>
                        <?php
                            echo $this->lang->line('verification_product_key');
                        ?>
                    </label>
                    <input type="text" class="ser" id="product_key" name="product_key" />
                        <?php

                        ?>
                    <button type="submit">
                        <?php
                            echo $this->lang->line('verification_button');
                        ?>
                    </button>
                    <div id="status">
                        <h2>
                            <?php
                                echo $this->lang->line('verification_status');
                            ?>
                        </h2>
                        <div class="status" id="verify">
                            <?php
                                echo $this->lang->line('verification_initial_setting');
                            ?>
                        </div>
                        <div class="status" id="services">
                            <?php
                                echo $this->lang->line('verification_initial_service');
                            ?>
                        </div>
                        <div class="status" id="accounts">
                            <?php
                                echo $this->lang->line('verification_initial_accounts');
                            ?>
                        </div>
                        <div class="status" id="accounts_services">
                            <?php
                                echo $this->lang->line('verification_initial_agent_service');
                            ?>
                        </div>
                        <div class="status" id="complete">
                            <?php
                                echo $this->lang->line('verification_complete');
                            ?>
                        </div>
                        <div id="note_spc">
                    </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
